JDK: 1.8
SpringBoot: 1.5.10.RELEASE
Maven pom.xml 配置
引入 starter
继承 starter parent pom
1 | <!-- Inherit defaults from Spring Boot --> |
不继承 starter parent pom
1 | <dependencyManagement> |
推荐使用 不继承 starter parent pom 的方式。
spring-boot-dependencies
对 SpringBoot 应用程序所需的 jar 版本进行统计管理,
简化 Java EE 程序 jar 包依赖的管理,减少 jar 包依赖的冲突。
改变 Java 版本
1 | <properties> |
使用 SpringBoot Maven 插件
1 | <build> |
引入 web starter
1 | <dependency> |
通过 spring-boot-starter-web
的引入,可以统一引入 Java Web 所需的 jar
实现 HelloWorld
浏览器发送 hello 请求,服务器接受请求并处理,响应 HelloWorld 字符串。
创建启动类
在 com.example.boot
包下创建类 BootApplication
:
1 | import org.springframework.boot.SpringApplication; |
在启动类上添加 @SpringBootApplication
注解
在 main
方法中添加 SpringApplication.run(BootApplication.class, args);
创建 Controller
在 com.example.boot.controller
包下创建 HelloWorldController
:
1 | import org.springframework.web.bind.annotation.RequestMapping; |
执行启动类 main 方法后,通过浏览器访问
http://localhost:8080/home
打包 SpringBoot 应用程序
利用 spring-boot-maven-plugin
插件创建可执行 jar
部署 SpringBoot 应用程序
利用 java -jar
命令执行 SpringBoot 应用程序可执行 jar